/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Fases;

import Negocio.NegocioMaterazzi;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;

/**
 *
 * @author Marcio
 */
public class FaseFazenda extends Fase {

    int[] seq = {100, 30};
    NegocioMaterazzi materazzi = new NegocioMaterazzi(seq, 50, 50);

    public FaseFazenda() {
        super();
        Image imgCenario = null;
        try {
            imgCenario = Image.createImage("/imagens/cenario1.jpg");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        this.cenario = new TiledLayer(1, 1, imgCenario, imgCenario.getWidth(), imgCenario.getHeight());
        int[][] tiles = {
            {1}
        };
        // write mid-init user code here
        for (int row = 0; row < 1; row++) {
            for (int col = 0; col < 1; col++) {
                cenario.setCell(col, row, tiles[row][col]);
            }
        }
        System.gc();
        
        System.out.println("CHEGOU AQUII");
        Image imgColisao = null;
      
        try {
            imgColisao = Image.createImage("/imagens/colisao1.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        this.colisao = new TiledLayer(1, 1, imgColisao, imgColisao.getWidth(), imgColisao.getHeight());

        int[][] tilesColisao = {
            {1}
        };
        // write mid-init user code here
        for (int row = 0; row < 1; row++) {
            for (int col = 0; col < 1; col++) {
                this.colisao.setCell(col, row, tilesColisao[row][col]);
            }
        }


    }

    public void jogar() {
        this.layerManager.append(this.materazzi.getSpriteMaterazzi());
        this.layerManager.append(this.bode.getSpriteBode());
        colisao.setPosition(0, 0);
        colisao.setVisible(true);


        cenario.setPosition(0, 0);
        cenario.setVisible(true);
        this.layerManager.append(cenario);
        this.layerManager.append(colisao);

        Graphics g = getGraphics();

        while (!this.interrupted) {
            this.movimentacaoBode();
            this.materazzi.movimentarMaterazzi();
            this.layerManager.paint(g, 0, 0);
            flushGraphics(0, 0, this.getWidth(), this.getHeight());

            try {
                Thread.sleep(20);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }

        }

    }
}
